﻿/// <reference path="KingsSharp.js" />
(function () {
    KingsSharp.GetGridFilter = function (tid) {
        var filterarr = new KingsSharp.filter.group();
        tid = $("body");
        var _targetsetobjectname = "data-source-obj";
        tid.find("*[data-filter]").each(function (i) {
            var _operater = $(this).attr("name");
            var _operaterid = $(this).attr("data-traget") || _operater;
            var _value = $("#operate_" + _operaterid).length != 0 ? $("#operate_" + _operaterid).val() : "equal";
            filterarr.Rules.push(new KingsSharp.filter.rule(_operater, $(this).val(), _value));
        });
        return filterarr;
    };
    KingsSharp.GridFilterInit = function (parmeter) {
        var _filterobject = this;
        var _targetsetobjectname = "data-source-obj";
        _filterobject.filter = new KingsSharp.filter.group();
        _filterobject.init = function () {
            var btnFilters = $(parmeter).find(".p-icon-filter-style");
            btnFilters.each(function () {
                var menudom = $(this).children();
                $(this).click(function () {
                    menudom.menu("show", {
                        left: $(this).offset().left,
                        top: $(this).offset().top + $(this).height() + 2,
                        onClick: function (item) {
                            menudom.find("input[name='" + $(item.target).attr(_targetsetobjectname) + "']").val(item.name);
                            menudom.find(".icon-ok").removeClass("icon-ok");
                            menudom.menu("setIcon", {
                                target: item.target,
                                iconCls: 'icon-ok'
                            });
                        }
                    });
                })
            });
        };
        this.init();
    };
})();